package fristphase.day9_14;

import java.util.ArrayList;
import java.util.Collection;

public class MyCollection {
    public static void main(String[] args) {
        Collection c = new ArrayList();
        c.add("one");
        c.add("two");
        System.out.println(c);//Collection重写了toString方法

        int size = c.size();
        System.out.println("size:"+size);

        boolean isEmpty = c.isEmpty();
        System.out.println("是不是空集："+isEmpty);

        c.clear();
        System.out.println("集合全部清空");
        System.out.println(c);
        System.out.println(c.size());
        System.out.println("是不是空集："+c.isEmpty());

        Collection c2 = new ArrayList();
        c2.add(new Point(1,2));
        c2.add(new Point(3,4));
        c2.add(new Point(5,6));
        c2.add(new Point(7,8));
        c2.add(new Point(9,0));

        System.out.println(c2);

        Point p = new Point(3,4);

        boolean contains = c2.contains(p);
        System.out.println("是否包含："+contains);
        c.remove(p);
        System.out.println(c);


        Collection c3 = new ArrayList();
        c3.add(p);
        System.out.println("p:"+p);
        System.out.println("c:"+c3);//集合以数组的方式输出

        p.setX(100);
        System.out.println("p:"+p);
        System.out.println("c"+c3);


        Collection c4 = new ArrayList();
        c4.add("java");
        c4.add("c++");
        c4.add(".net");
        System.out.println("c4:"+c4);

        Collection c5 = new ArrayList();
        c5.add("android");
        c5.add("ios");
        c5.add("java");
        System.out.println("c5:"+c5);
        c4.add(c5);
        System.out.println("c4:"+c4);
        System.out.println("c5:"+c5);

        Collection c6 = new ArrayList();
        c6.add("c++");
        c6.add("android");
        c6.add("php");
        System.out.println("c6:"+c6);
        System.out.println("--------------");

        System.out.println("c4"+c4);
        boolean contains1 = c4.containsAll(c6);//仅判断c4集合中是否包含c6集合中的所有元素
        System.out.println("包含所有："+contains1);

        c4.retainAll(c6);//将c4与c6的共有的对象抽出，赋给c4，而且会返回boolean值；
        System.out.println("c4:"+c4);
        System.out.println("c6:"+c6);
        System.out.println("------------");

        System.out.println("c5"+c5);
        c5.removeAll(c6);//将c4与c6的共有的对象,从c4中移除；
        System.out.println("c5:"+c5);
        System.out.println("c6:"+c6);
    }
}
